package task

import "sync"

var (
	groupOnce   sync.Once
	groupSingle *Group
)

type Group struct {
	// 每一个任务组下的当前运行的任务
	groupCurTask map[string]*Task
	smGroup      sync.Mutex
}

func GetTaskGroup() *Group {
	groupOnce.Do(func() {
		groupSingle = &Group{
			groupCurTask: make(map[string]*Task),
		}
	})
	return groupSingle
}

func (g *Group) SetGroupCurrentTask(GroupName string, task *Task) {
	g.smGroup.Lock()
	defer g.smGroup.Unlock()
	g.groupCurTask[GroupName] = task
}

func (g *Group) GetGroupCurrentTask(GroupName string) *Task {
	return g.groupCurTask[GroupName]
}
